package com.whfc.ms.api.quality.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.quality.service.MsQualityAcceptanceService;
import com.whfc.quality.dto.QualityAcceptanceDTO;
import com.whfc.quality.param.QualityAcceptanceAddParam;
import com.whfc.quality.param.QualityAcceptanceEditParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author: hw
 * @date: 2021-10-30 9:31
 * @description: 验收情况
 */
@RestController
@RequestMapping("/ms/api/quality/acceptance")
public class QualityAcceptanceController  extends BaseController {

    @Autowired
    private MsQualityAcceptanceService qualityAcceptanceService;


    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody QualityAcceptanceAddParam param) {
        logger.info("新增验收情况,loginer:{},param:{}", user.getUsername(), param);
        qualityAcceptanceService.add(param);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @Validated @RequestBody QualityAcceptanceEditParam param) {
        logger.info("修改验收情况,loginer:{},param:{}", user.getUsername(), param);
        qualityAcceptanceService.edit(param);
        return ResultUtil.success();
    }

    @GetMapping("details")
    public Result details(@SessionAttribute(SessionAttr.MS_USER) SysUser user, @RequestParam("deptId") Integer deptId,
                          @RequestParam(value = "time", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date time) {
        logger.info("修改验收情况,loginer:{},deptId:{},time:{}", user.getUsername(), deptId,time);
        QualityAcceptanceDTO data = qualityAcceptanceService.details(deptId, time);
        return ResultUtil.success(data);
    }
}
